﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Moq;

namespace MvcWiki.Test.Repository.FileSystem.WikiPageFileSystemRepository
{
    public class GetAllWikiPagesFacts
    {
        [Fact]
        public void Can_Call()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            IList<MvcWiki.Model.WikiPage> wikiPages = wikiPageRepository.GetAllWikiPages("Namespace");
        }

        [Fact]
        public void Checks_Whether_WikiNamespace_Directory_Exists()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            wikiPageRepository.GetAllWikiPages("Namespace");

            fileSystem.VerifyAll();
        }

        [Fact]
        public void Throws_Exception_If_WikiNamespace_Directory_Does_Not_Exist()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { });

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            Assert.Throws<MvcWiki.Exceptions.NamespaceDoesNotExistException>(
                () => wikiPageRepository.GetAllWikiPages("Namespace"));
        }

        [Fact]
        public void Gets_All_WikiPage_Directories()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var directories = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetDirectories(String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id), "*---*")).Returns(directories);

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            wikiPageRepository.GetAllWikiPages("Namespace");

            fileSystem.VerifyAll();
        }

        [Fact]
        public void Gets_All_WikiRevision_Txt_Files_For_Every_WikiPage()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var directories = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetDirectories(String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id), "*---*")).Returns(directories);

            var revisions1 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101020000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101030000.txt", wikiNamespace.Id)
            };

            var revisions2 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101020000.txt", wikiNamespace.Id),
            };

            var revisions3 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3\\r---20090101000000.txt", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id), "r---*.txt")).Returns(revisions1);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id), "r---*.txt")).Returns(revisions2);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id), "r---*.txt")).Returns(revisions3);

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            wikiPageRepository.GetAllWikiPages("Namespace");

            fileSystem.VerifyAll();
        }

        [Fact]
        public void Reads_All_WikiRevision_Txt_Files_For_Every_WikiPage()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var directories = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetDirectories(String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id), "*---*")).Returns(directories);

            var revisions1 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101020000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101030000.txt", wikiNamespace.Id)
            };

            var revisions2 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101020000.txt", wikiNamespace.Id),
            };

            var revisions3 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3\\r---20090101000000.txt", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id), "r---*.txt")).Returns(revisions1);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id), "r---*.txt")).Returns(revisions2);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id), "r---*.txt")).Returns(revisions3);

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101010000.txt", wikiNamespace.Id))).Returns("Page1 revision1");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101020000.txt", wikiNamespace.Id))).Returns("Page1 revision2");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101030000.txt", wikiNamespace.Id))).Returns("Page1 revision3");

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101010000.txt", wikiNamespace.Id))).Returns("Page2 revision1");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101020000.txt", wikiNamespace.Id))).Returns("Page2 revision2");

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3\\r---20090101000000.txt", wikiNamespace.Id))).Returns("Page3 revision1");

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            wikiPageRepository.GetAllWikiPages("Namespace");

            fileSystem.VerifyAll();
        }

        [Fact]
        public void Calls_IWikiNamespaceRepsotory_GetWikiNamespace()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();
            wikiNamespaceRepository.Setup(x => x.GetWikiNamespace("Namespace")).Returns(wikiNamespace);

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            wikiPageRepository.GetAllWikiPages("Namespace");

            wikiNamespaceRepository.VerifyAll();
        }

        [Fact]
        public void Returns_IList_Of_WikiPages_With_WikiNamespace_And_WikiRevisions()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace", Markup = new MvcWiki.Model.WikiMarkup() };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();
            wikiNamespaceRepository.Setup(x => x.GetWikiNamespace("Namespace")).Returns(wikiNamespace);

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var directories = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetDirectories(String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id), "*---*")).Returns(directories);

            var revisions1 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101020000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101030000.txt", wikiNamespace.Id)
            };

            var revisions2 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101010000.txt", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101020000.txt", wikiNamespace.Id),
            };

            var revisions3 = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3\\r---20090101000000.txt", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id), "r---*.txt")).Returns(revisions1);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id), "r---*.txt")).Returns(revisions2);
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id), "r---*.txt")).Returns(revisions3);

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101010000.txt", wikiNamespace.Id))).Returns("Page1 revision1");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101020000.txt", wikiNamespace.Id))).Returns("Page1 revision2");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1\\r---20090101030000.txt", wikiNamespace.Id))).Returns("Page1 revision3");

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101010000.txt", wikiNamespace.Id))).Returns("Page2 revision1");
            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2\\r---20090101020000.txt", wikiNamespace.Id))).Returns("Page2 revision2");

            fileSystem.Setup(x => x.ReadFromFile(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3\\r---20090101000000.txt", wikiNamespace.Id))).Returns("Page3 revision1");

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            var wikiPages = wikiPageRepository.GetAllWikiPages("Namespace");

            Assert.Equal<int>(3, wikiPages.Count);

            Assert.Equal<string>("Page1", wikiPages[0].Name);
            Assert.Equal<string>("Namespace", wikiPages[0].Namespace.Name);
            Assert.IsAssignableFrom<MvcWiki.Model.WikiMarkup>(wikiPages[0].Namespace.Markup);

            Assert.Equal<int>(3, wikiPages[0].Revisions.Count);

            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 01, 00, 00, DateTimeKind.Utc), wikiPages[0].Revisions[0].Created);
            Assert.Equal<string>("Page1 revision1", wikiPages[0].Revisions[0].Content);
            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 02, 00, 00, DateTimeKind.Utc), wikiPages[0].Revisions[1].Created);
            Assert.Equal<string>("Page1 revision2", wikiPages[0].Revisions[1].Content);
            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 03, 00, 00, DateTimeKind.Utc), wikiPages[0].Revisions[2].Created);
            Assert.Equal<string>("Page1 revision3", wikiPages[0].Revisions[2].Content);

            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 01, 00, 00, DateTimeKind.Utc), wikiPages[1].Revisions[0].Created);
            Assert.Equal<string>("Page2 revision1", wikiPages[1].Revisions[0].Content);
            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 02, 00, 00, DateTimeKind.Utc), wikiPages[1].Revisions[1].Created);
            Assert.Equal<string>("Page2 revision2", wikiPages[1].Revisions[1].Content);

            Assert.Equal<DateTime>(new DateTime(2009, 01, 01, 00, 00, 00, DateTimeKind.Utc), wikiPages[2].Revisions[0].Created);
            Assert.Equal<string>("Page3 revision1", wikiPages[2].Revisions[0].Content);
        }

        [Fact]
        public void Returns_IList_Of_WikiPages_With_Revision_Not_Null()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace { Name = "Namespace" };

            var wikiNamespaceRepository = new Mock<MvcWiki.Repository.IWikiNamespaceRepository>();

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            repositoryFactory.Setup(x => x.GetWikiNamespaceRepository()).Returns(wikiNamespaceRepository.Object);

            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();

            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();
            fileSystem.Setup(x => x.GetDirectories("c:\\path", "Namespace---*")).Returns(new string[] { String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id) });

            var directories = new string[] {
                String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id),
                String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id)
            };

            fileSystem.Setup(x => x.GetDirectories(String.Format("c:\\path\\Namespace---{0}", wikiNamespace.Id), "*---*")).Returns(directories);

            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page1---9f878f17-21bb-4fb1-a68e-3cd2c61201c1", wikiNamespace.Id), "r---*.txt")).Returns(new string[] { });
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page2---9f878f17-21bb-4fb1-a68e-3cd2c61201c2", wikiNamespace.Id), "r---*.txt")).Returns(new string[] { });
            fileSystem.Setup(x => x.GetFiles(String.Format("c:\\path\\Namespace---{0}\\Page3---9f878f17-21bb-4fb1-a68e-3cd2c61201c3", wikiNamespace.Id), "r---*.txt")).Returns(new string[] { });

            var wikiPageRepository = new MvcWiki.Repository.FileSystem.WikiPageFileSystemRepository(repositoryFactory.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            var wikiPages = wikiPageRepository.GetAllWikiPages("Namespace");

            Assert.NotNull(wikiPages[0].Revisions);
            Assert.NotNull(wikiPages[1].Revisions);
            Assert.NotNull(wikiPages[2].Revisions);
        }
    }
}